package com.vincent.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R {
    private int status;
    private String msg;
    private Map<String,Object> data;

    public static R ok(int status,String msg){
        R r = new R();
        r.status = status;
        r.msg = msg;
        return r;
    }

    public static R ok(){
        return R.ok(200,"ok");
    }

    public static R ok(String msg){
        return R.ok(200,msg);
    }

    public static R error(int status,String msg){
        R r = new R();
        r.status = status;
        r.msg = msg;
        return r;
    }

    public static R error(String msg){
        return R.error(500,msg);
    }

    public static R error(){
        return R.error("error");
    }

    public R put(String key,Object value){
        this.data = this.data == null ? new HashMap<>() : this.data;
        this.data.put(key,value);
        return this;
    }
}
